/**
 * 
 */
package com.base.myproject.client.busi.b2c.manager;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.JDBCModelData;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGrid;
import com.extjs.gxt.charts.client.Chart;
import com.extjs.gxt.charts.client.model.BarDataProvider;
import com.extjs.gxt.charts.client.model.ChartModel;
import com.extjs.gxt.charts.client.model.Legend;
import com.extjs.gxt.charts.client.model.LineDataProvider;
import com.extjs.gxt.charts.client.model.ScaleProvider;
import com.extjs.gxt.charts.client.model.Legend.Position;
import com.extjs.gxt.charts.client.model.charts.BarChart;
import com.extjs.gxt.charts.client.model.charts.LineChart;
import com.extjs.gxt.charts.client.model.charts.BarChart.BarStyle;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author zgw
 *2009-8-24 下午01:25:00
 * javazgw@gmail.com
 */
public class ChartTest {

	public ChartTest()
	{
		init();
	}
	void init()
	{
		
	}
	public Widget aa()
	{
		ContentPanel panel = new ContentPanel();
		panel.setAutoHeight(true);
		ToolBar tb = new ToolBar();
		Button addsuit = new Button("从商品库里添加套装商品");
		addsuit.setIconStyle("b2csuit");
		panel.setHeading("商品库，如果加入套装你必须先选择一行（必选）");
		tb.add(addsuit);
		panel.setTopComponent(tb);
		//addsuit.addListener(Events.Select, this);
		panel.setAutoWidth(true);
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		ColumnConfig gcode = new ColumnConfig("gcode", "商品大类编码", 100);
		TextField<String> gcodetext = new TextField<String>();
		gcode.setEditor(new CellEditor(gcodetext));
		columns.add(gcode);
		ColumnConfig gname = new ColumnConfig("discountprice", "商品大类名称", 100);
		TextField<String> gnametext = new TextField<String>();
		gname.setEditor(new CellEditor(gnametext));
		columns.add(gname);

		ColumnConfig treecode = new ColumnConfig("price", "商品分类树编码", 100);

		TextField<String> treecodetext = new TextField<String>();
		treecode.setEditor(new CellEditor(treecodetext));
		columns.add(treecode);

		ColumnConfig b2cgcodecolumn = new ColumnConfig("b2cgcode", "商品编码", 100);
		TextField<String> b2cgcodetext = new TextField<String>();
		b2cgcodecolumn.setEditor(new CellEditor(b2cgcodetext));
		columns.add(b2cgcodecolumn);
		ColumnConfig b2cgname = new ColumnConfig("b2cgname", "商品名称", 100);
		TextField<String> b2cgnametext = new TextField<String>();
		b2cgname.setEditor(new CellEditor(b2cgnametext));
		columns.add(b2cgname);

		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");

		type.addField("gcode");
		type.addField("gname");
		type.addField("b2cgcode");
		type.addField("price");
		type.addField("discountprice");
		type.addField("b2cgname");
		type.addField("mainimagepath");
		type.addField("treecode");
		type.addField("detailimage");
		
		
		
	    
	    
		StoreInfo info = new StoreInfo();

		info.setTablename("b2cgcode");
		info.setKeyname(new String[] { "b2cgcode" });
		info.setSql("select * from b2cgcode");
		 BaseStore<JDBCModelData> store = new BaseStore<JDBCModelData>(type, info);
		 
		 
		 ChartModel model = new ChartModel("Team Sales by Month",  
	        "font-size: 14px; font-family: Verdana; text-align: center;");  
	    model.setBackgroundColour("#fefefe");  
	    model.setLegend(new Legend(Position.TOP, true));  
	    model.setScaleProvider(ScaleProvider.ROUNDED_NEAREST_SCALE_PROVIDER);  
	    
	    BarChart bar = new BarChart(BarStyle.GLASS);  
	    bar.setColour("#00aa00");  
	    BarDataProvider barProvider = new BarDataProvider("price", "b2cgname");  
	    barProvider.bind(store);  
	    bar.setDataProvider(barProvider);  
	  //  bar.addChartListener(listener);  
	    model.addChartConfig(bar);  
	    

	    
	    bar = new BarChart(BarStyle.GLASS);  
	    bar.setColour("#ff6600");  
	    barProvider = new BarDataProvider("discountprice");  
	    barProvider.bind(store);  
	    bar.setDataProvider(barProvider);  
	   // bar.addChartListener(listener);  
	    model.addChartConfig(bar);  
	    
	    LineChart line = new LineChart();  
	    line.setAnimateOnShow(true);  
	    line.setText("Average");  
	    line.setColour("#FF0000");  
	    LineDataProvider lineProvider = new LineDataProvider("discountprice");  
	    lineProvider.bind(store);  
	    line.setDataProvider(lineProvider);  
	    model.addChartConfig(line);  
	    
/*	    PieChart pie = new PieChart();  
	    PieDataProvider piedataprovider = new PieDataProvider("discountprice");
	    piedataprovider.bind(store);
	    pie.setDataProvider(piedataprovider);
	    model.addChartConfig(pie);*/
	    
	    
	    
	    String url = "chart/open-flash-chart.swf";
	    final Chart chart = new Chart(url);  
	    chart.setChartModel(model);  
	    chart.setHeight("300px");
	    ContentPanel cp = new ContentPanel();
	    cp.setHeading("Chart");  
	    cp.add(chart);  
		ColumnModel cm = new ColumnModel(columns);
		BaseGrid grid = new BaseGrid(store, cm);
		grid.setHeight("300px");
		cp.add(grid);
		return cp;
	}
}
